package com.jackstraw.jack_base.job.xxljob.bean;

import com.jackstraw.jack_base.util.JsonUtil;
import com.jackstraw.jack_base.util.tenant.contextholder.TenantContextHolder;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.IJobHandler;

/**
 * Job实现类
 *
 * @param <T>
 */
public abstract class AbstractXxlJobHandler<T> extends IJobHandler {

    @Override
    public void execute() throws Exception {
        String jobParam = XxlJobHelper.getJobParam();
        ExecutorParam<T> executorParam = JsonUtil.getJsonToBean(jobParam, ExecutorParam.class);
        String tenantName = executorParam.getTenantName();
        TenantContextHolder.set(tenantName);
        T param = executorParam.getParam();
        this.commonExecute(param);
    }

    protected abstract void commonExecute(T param);

}
